package cn.yunyichina.provider.pay.icbc.utils;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class PayUtil {

	/**
	 * 生成自动提交的表单
	 * @param postData
	 * @param gateWay
	 * @return
	 */
	public static String createReturnHtml(Map<String, String> postData,
			String gateWay) {
		StringBuilder sb = new StringBuilder();
		//sb.append("<script language=\"javascript\">window.onload=function(){document.Return_form.submit();return false;}</script>");
		sb.append("<form id=\"Return_form\" name=\"pay_form\" action=\"")
				.append(gateWay).append("\" method=\"post\">");
		Iterator<Entry<String, String>> it = postData.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> en = it.next();
			sb.append("<input type=\"hidden\" name=\"" + en.getKey()
					+ "\" id=\"" + en.getKey() + "\" value=\"" + en.getValue()
					+ "\" />");
		}
//		sb.append("<input type=\"submit\" value=\"提交数据\" />");
		sb.append("</form>");
		return sb.toString();
	}
	
	public static String createFormHtml(Map<String, String> postData,
			String gateWay) {
		StringBuilder sb = new StringBuilder();
		sb.append("<form name=\"sendpost\" method=\"post\" action=\"")
				.append(gateWay).append("\" >");
		Iterator<Entry<String, String>> it = postData.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> en = it.next();
			sb.append("<input type=\"hidden\" name=\"" + en.getKey()
					+ "\" id=\"" + en.getKey() + "\" value=\"" + en.getValue()
					+ "\" />");
		}
		sb.append("<input type=\"submit\" value=\"提交数据\" />");
		sb.append("</form>");
		return sb.toString();
	}
}
